package team.cdlzz.controller;

import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import team.cdlzz.model.pojo.Course;
import team.cdlzz.model.pojo.CourseDetail;
import team.cdlzz.model.pojo.Exam;
import team.cdlzz.model.pojo.Question;
import team.cdlzz.service.CourseService;

import java.util.*;

/**
 * @author zw
 * @date 2022-06-25.
 */
@RestController
@Log4j
@RequestMapping("/course")
public class CourseController {
    @Autowired
    CourseService courseService;

    /**
     * TODO:获取所有课程的单例信息
     * @return 返回所有课程的单例信息
     */
    @RequestMapping("/getCourseList")
    public List<Course> getCourseList(){
        return courseService.getCourseList();
    }

    @RequestMapping("/getCourseInfoList")
    public List GetCourseInfoList(){
        return courseService.GetCourseInfoList();
    }

    @RequestMapping("/getLikeCourse")
    public PageInfo getCourseInfo(@RequestParam(value = "like",defaultValue = "") String like, @RequestParam(value = "pageNo", defaultValue ="1") Integer pageNo, @RequestParam(value = "pageSize", defaultValue ="5")Integer pageSize){
            return courseService.getCourseInfo(like,pageNo,pageSize);
    }

//    @RequestMapping("/getCidFile")
//    public
    @RequestMapping("getCourseFile")
    public List getCourseListFile(Integer cid){
        return courseService.getCourseListFile(cid);
    }

    @RequestMapping("/getCoursebyID")
    public CourseDetail getCourseDetail(Integer cid){
       return courseService.getCoursebyID(cid);
    }

    @RequestMapping("/createCourse")
    public String createCourse(@RequestParam("uid") Integer uid ,@RequestParam("Teacher_Name") String t_name,
                               @RequestParam("Class_Name") String c_Name ,@RequestParam("Teacher_Detail") String t_Detail,
                               @RequestParam("StartTime") String startTime ,@RequestParam("End_Time") String endTime,
                               @RequestParam("Hour_Arrangement") String hourArrangement,@RequestParam("Class_Information")String cDetails
            ,@RequestParam("Class_Information") String cInformation,
                               @RequestParam("route") String  file) {

        if (t_name!=null&&!"".equals(t_name) &&c_Name!=null&&  !"".equals(c_Name)  &&
                t_Detail!=null&&!"".equals(t_Detail) && uid != null
                && uid != 0 &&  startTime!=null&&!"".equals(startTime)&&
                endTime!=null&&!"".equals(endTime) &&hourArrangement!=null&&  !"".equals(hourArrangement)  &&
                cInformation!=null&&!"".equals(cInformation)&&cDetails!=null&&!"".equals(cDetails) &&file!=null&&!"".equals(file)){
            return courseService.CreateCourse( uid ,t_name, c_Name , t_Detail, startTime , cDetails,
                    endTime, hourArrangement , cInformation, file);
        }

        System.out.println("有空值");
        return "添加失败";
    }

//    @RequestMapping("/createCourse")
//    public String createCourse(@RequestBody String str) {
//        System.out.println(str);
//        return "添加失败";
//    }


    @RequestMapping("/createExam")
    public String createExam(
    @RequestParam("cid") Integer cid,@RequestParam("title") String title,
    @RequestParam("startTime")  String startTime,
    @RequestParam("endTime")  String endTime,
    @RequestParam("grade")  Integer grade,
    @RequestParam("num")  Integer num){
        Exam exam = new Exam(null,cid,title,startTime,endTime,grade,num);
        return courseService.createExam(exam);
    }

    @RequestMapping("/getExamList")
    public List<Exam> getExamList(@RequestParam("cid") Integer cid){
        return courseService.ExamListByCid(cid);

    }   @RequestMapping("/getExamListFlag")
    public List<Exam> getExamList(@RequestParam("cid") Integer cid,@RequestParam("uid")Integer uid){
        return courseService.ExamListByCid(cid,uid);
    }

    @RequestMapping("/userSetCourse")
    public String userSetCourse(@RequestParam("uid") Integer uid, @RequestParam("cid") Integer cid) {
        return courseService.userSetCours(uid,cid);
    }


}

